package com.totoro.motan.config;

import com.weibo.api.motan.config.ProtocolConfig;
import com.weibo.api.motan.config.RegistryConfig;
import com.weibo.api.motan.config.springsupport.AnnotationBean;
import com.weibo.api.motan.config.springsupport.BasicServiceConfigBean;
import com.weibo.api.motan.config.springsupport.ProtocolConfigBean;
import com.weibo.api.motan.config.springsupport.RegistryConfigBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.util.StringUtils;

/**
 * Motan通用配置
 */
@Configuration
public class MotanConfig {

    /**
     * Motan扫描包路径配置
     * @param scanPackage
     * @return
     */
    @Bean
    public AnnotationBean motanAnnotationBean(@Value("${motan.annotation}") String scanPackage){
        AnnotationBean annotationBean = new AnnotationBean();
        if(!StringUtils.isEmpty(scanPackage))
            annotationBean.setPackage(scanPackage);
        return annotationBean;
    }

    /**
     * Motan协议配置
     * @return
     */
    @Bean(name = "motan")
    @ConfigurationProperties(prefix = "motan.protocol")
    public ProtocolConfig protocolConfig(){
        ProtocolConfig protocolConfig = new ProtocolConfig();
        return protocolConfig;
    }

    @Bean(name = "registry_zookeeper")
    @ConfigurationProperties(prefix = "motan.registry")
    public RegistryConfig registryConfig(){
        RegistryConfig registryConfig = new RegistryConfig();
        return registryConfig;
    }

}
